<?php
	include_once 'functions.php';

	$nome = $_POST["nome"];
	$email = $_POST["email"];
	$password = $_POST["password"];
	$enc_password = md5($password);
	$con = getdb();

	$query = "INSERT INTO usuarios(name, email, encrypted_password, role, created_at) VALUES ('".$nome."','".$email."','".$enc_password."','user',NOW())";
	$result = pg_query($query);

	if (!$result){
		pg_query($con, "ROLLBACK");
		header("Location: /labua");
	}
	else {
		session_start();
		$_SESSION['email'] = $email;
		header("Location: /labua");
	}
	pg_close($con);
?>